GBML manual / Collision

collides

True if this instance’s own box currently overlaps other’s.

Syntax

collides(other) -> bool

Arguments

NameType
otherref<object>

Returns

bool

Description

True if this instance's own box currently overlaps other's. The direct instance-to-instance "are these two touching right now" check, for code that already has a specific instance reference in hand rather than a position to test - the box-only test pos_meeting/point_meeting run against a plain rectangle, applied to two real instances instead.

An instance destroyed earlier in the same frame still counts for this check until the end of the frame, because instance_destroy only ends it then. The one exception is a Collision event, which skips it at once.

An instance with no sprite and no mask size is a single point. A box meets that point only when the point is strictly inside it - past its left and top edges and short of its right and bottom edges. A point exactly on an edge or a corner is not met, and two boxes with no size never meet. (Overlap and collision has the whole rule.)

Example

var target = instance_nearest(x, y, obj_doc_enemy);
if (target != nothing && collides(target)) {
    instance_destroy(target);
}

Re-picks the nearest obj_doc_enemy every step and destroys it only once this instance's own box actually touches it - finding a target and confirming contact with it are two separate checks.

On the GBA

Box-only - the same box mask_w/mask_h/mask_x/mask_y (or mask_sprite/sprite) resolve to and box_left/box_right/box_top/box_bottom report, not a per-pixel test. An instance with no sprite and no mask size is a single point at its x and y (moved by mask_x and mask_y). A box meets that point only when the point lies strictly inside it, past its left and top edges and short of its right and bottom edges; a point exactly on an edge or a corner is not met, and two boxes with no size never meet, even in the same spot. A box with a width and no height (or the reverse) is a line, met when it lies strictly between the edges of the other box across its empty side. A Collision event is the exception: it never meets an instance with no width or no height.

See also: pos_meetinginstance_nearest